import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;

/**
 * Displays the information for Hostess (reservations and waitlist) and Managers (reservations, employees, and menu items)
 *
 */
public class GridsWindow extends JPanel {

	private JPanel mainPanel;
	private JPanel leftPanel;
	private JPanel centerPanel;
	private JPanel bottomPanel;
	private JPanel nameBar;
	private JPanel leftMenu;

	private JLabel nameTime;

	private static int managerSelection; //indicates which button was clicked from the manager menu

	int xSize;
	int ySize;

	private static String buttonName;

	private static ArrayList<String> resHeaders;
	private static ArrayList<String> empHeaders;
	private static ArrayList<String> menuHeaders;

	private static int userID;
	private static int userJobCode;
	private static String userName;

	/**
	 * Constructor for the GridsWindow object. Takes an ID and job code as input and
	 * creates the proper layout for each job role.
	 * 
	 * @param id
	 *            The id of the current user.
	 * @param jobCode
	 *            The job code of the current user. 0 = Hostess, 2 =  Manager
	 * @param name
	 *            The last name of the current user.
	 */
	public GridsWindow(int id, int jobCode, String name){
		//set initial variables
		userID = id;
		userJobCode = jobCode;
		userName = name;
		//setButtonNameText("");

		setWindowSize();
		initializePanels();

		buildBottomGridPanel();
		buildLeftPanel(userJobCode);
		buildGridsPanel(userJobCode);

		mainPanel.add(bottomPanel, BorderLayout.PAGE_END);
		mainPanel.add(leftPanel, BorderLayout.LINE_START);
		mainPanel.add(centerPanel, BorderLayout.CENTER);
		add(mainPanel);

	}//End of Constructor


	/**
	 * Creates an instance of the Grids class and adds to the center panel
	 */
	private void buildGridsPanel(int jc) {
		ArrayList<String> headerArray = getHeaderData(jc);
		ArrayList<String> rowData = getRowData(jc);
		int totalCol = headerArray.size();
		int totalRow = rowData.size()/totalCol;

		Grids g = new Grids(totalCol, headerArray, totalRow, rowData);
		centerPanel.add(g);
	}//End buildTicketPanel method


	/**
	 * Obtains the information already stored in the database to display.  If none can be found, a blank arraylist is returned
	 * @param jc - the jobCode of the user
	 * @return an ArrayList containing the information stored in the database based on what information the user has chosen
	 */
	private ArrayList<String> getRowData(int jc) {

		/**** NEED DISPLAY FOR RESERVATION/WAITLIST ****/ 

		if(jc==2 && buttonName.equals("Employees")){
			return displayEmployees();
		}

		if(jc==2 && buttonName.equals("Menu Items")){
			return displayMenuItems();
		}
		
		if(jc==2 && buttonName.equals("Reservations")) {
			return displayReservations();
		}
		
		if(jc==0 && buttonName.equals("Reservations")) {
			return displayReservations();
		}
		if(jc==0 && buttonName.equals("WaitList")){
			return displayWaitList();
	}
		ArrayList<String> blankTest = new ArrayList<String>();
		for (int i = 0; i < 31; i++) {
			blankTest.add("");
		}
		return blankTest;
	}//End getRowData method

	private ArrayList<String> displayWaitList() {
		ArrayList<String> blankTest = new ArrayList<String>();
		//		for (int i = 0; i < 51; i++){
		//			blankTest.add("");
		//		}

		blankTest.add("11/05/2015");
		blankTest.add("09:30");
		blankTest.add("4");
		blankTest.add("Jones");
		blankTest.add("999-999-9999");
		blankTest.add("");
		blankTest.add("12/05/2015");
		blankTest.add("07:30");
		blankTest.add("6");
		blankTest.add("Carter");
		blankTest.add("999-999-9999");
		blankTest.add("Test");
		blankTest.add("09/10/2015");
		blankTest.add("05:30");
		blankTest.add("2");
		blankTest.add("Barlow");
		blankTest.add("999-999-9999");
		blankTest.add("Test 2");
		return blankTest;
	}


	/**
	 * Creates an ArrayList<String> of all menu items currently listed in the database
	 * @return menuList - an ArrayList<String> of menu items currently listed in the database
	 */
	private ArrayList<String> displayMenuItems() {
		ArrayList<String> menuList = new ArrayList<String>();

		// Database call to get the menu information
		Connection c = null;
		ResultSet menuResults;
		try {
			c = SqliteHelper.getConn();

			Statement menuData = c.createStatement();
			String menuSelectQuery = "SELECT * FROM Menu;";
			menuResults = menuData.executeQuery(menuSelectQuery);

			while (menuResults.next()) {
				menuList.add(menuResults.getString("Item_Name"));
				menuList.add(menuResults.getString("Item_Price"));
				menuList.add(menuResults.getString("Item_Activity"));
				menuList.add(menuResults.getString("General_Cat"));
				menuList.add(menuResults.getString("Specific_Cat"));
			}
			return menuList;
		} catch (Exception e) {
			System.err.println("Database Call Failure in menuItemsPanel.");
			System.err.println(e.getClass().getName() + ": " + e.getMessage());
			return null;
		}
	}//End displayMenuItems method


	private ArrayList<String> displayReservations() {
		ArrayList<String> activeReservationList = SqliteHelper.GetActiveReservations();
		return activeReservationList;
	}
	/**
	 * Creates an ArrayList<String> of all employees currently listed in the database
	 * @return employeeList - an ArrayList<String> of employees currently listed in the database
	 */
	private ArrayList<String> displayEmployees() {
		// Database call to get the employee information
		Connection c = null;
		ResultSet employeeResults;
		try {
			c = SqliteHelper.getConn();
			ArrayList<String> employeeList = new ArrayList<String>();
			Statement empSelectStatement = c.createStatement();
			String empSelectQuery = "SELECT * FROM Employee;";
			employeeResults = empSelectStatement.executeQuery(empSelectQuery);

			while (employeeResults.next()) {
				employeeList.add(employeeResults.getString("FullName"));

				employeeList.add(employeeResults.getString("Employee_ID"));

				employeeList.add(employeeResults.getString("Weekly_Hours"));

				int empJobCode = employeeResults.getInt("Job_Code");
				switch (empJobCode) {
				case 0:
					employeeList.add("Hostess");
					break;
				case 1:
					employeeList.add("Server");
					break;
				case 2:
					employeeList.add("Manager");
				}
				employeeList.add(employeeResults.getString("Notes"));
			}
			return employeeList;

		} catch (Exception ex) {
			System.err.println("Database Call Failure in employeesPanel.");
			System.err
			.println(ex.getClass().getName() + ": " + ex.getMessage());
			return null;
		}

	}//end displayEmployees method


	/**
	 * Creates an ArrayList<String> to be used as input to create the column names of the Grids instance
	 * @param jc - the job code of the user
	 * @return - an ArrayList<String> containing the column names
	 */
	private ArrayList<String> getHeaderData(int jc) {
		if(jc == 0 || (jc == 2 && managerSelection == 1)){
			resHeaders = new ArrayList<String>();
			resHeaders.add("Date");
			resHeaders.add("Time");
			resHeaders.add("# In Party");
			resHeaders.add("Name");
			resHeaders.add("Phone Number");
			resHeaders.add("Notes");
			return resHeaders;
		}
		else{
			if (managerSelection == 2){
				empHeaders = new ArrayList<String>();
				empHeaders.add("Name");
				empHeaders.add("Password");
				empHeaders.add("Hours/Week");
				empHeaders.add("Job Code");
				empHeaders.add("Notes");
				return empHeaders;
			}
			else{
				menuHeaders = new ArrayList<String>();
				menuHeaders.add("Item Name");
				menuHeaders.add("Item Price");
				menuHeaders.add("Item Activity");
				menuHeaders.add("Food/Drink");
				menuHeaders.add("Specific Category");
				return menuHeaders;
			}	
		}//End outer if/else statement
	}//End getHeaderData method

	/**
	 * Builds the leftPanel which consists of the user's name/date and the menu choices depending on job code
	 * @param jc - the user Job Code (0 = hostess, 2 = manager)
	 */
	private void buildLeftPanel(int jc) {
		buildNameBar();
		buildMenu(jc);

		leftPanel.add(nameBar, BorderLayout.PAGE_START);
		leftPanel.add(leftMenu);
	}//End buildLeftPanel method


	/**
	 * Builds the list of menu items to be placed on the leftMenu
	 * @param jc - the user Job Code (0 = hostess,  2 = manager)
	 */
	private void buildMenu(int jc) {
		leftMenu = new JPanel();
		leftMenu.setLayout(new GridLayout(3, 3));

		createGridsButtons(jc);

		leftMenu.setSize(500, 500);
	}//End buildMenu method

	/**
	 * Create the menu buttons for the either the Hostess or Manager - to be added to the leftPanel
	 */
	private void createGridsButtons(int jc) {
		JButton addButton = new JButton ("Add");
		addButton.setFont(new Font("Arial", Font.PLAIN, 40));
		addButton.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				if (buttonName.equals("Reservations")){
					addReservation();
				}
				if (buttonName.equals("Employees")){
					addEmployee();
				}
				if (buttonName.equals("Menu Items")){
					addMenuItems();
				}
				if (buttonName.equals("WaitList")){
					addWaitList();
				}
				
			}

		});//End ActionListener

		JButton editButton = new JButton ("Edit");
		editButton.setFont(new Font("Arial", Font.PLAIN, 40));
		editButton.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				if (buttonName.equals("Reservations")){
					editReservation();
				}
				if (buttonName.equals("WaitList")){
					editWaitList();
				}
				if (buttonName.equals("Employees")){
					editEmployee();
				}
				if (buttonName.equals("Menu Items")){
					editMenuItems();
				}
			}

		});//End ActionListener

		JButton deleteButton = new JButton ("Delete");
		deleteButton.setFont(new Font("Arial", Font.PLAIN, 40));
		deleteButton.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				if (buttonName.equals("Reservations")){
					deleteReservation();
				}
				if (buttonName.equals("WaitList")){
					deleteWaitList();
				}
				if (buttonName.equals("Employees")){
					deleteEmployee();
				}
				if (buttonName.equals("Menu Items")){
					deleteMenuItems();
				}
			}

		});//End ActionListener

		leftMenu.add(addButton);
		leftMenu.add(editButton);
		leftMenu.add(deleteButton);
	}//End createManagerButtons method

	/**
	 * Removes a selected item from the database and display
	 */
	private void deleteMenuItems() {
		ArrayList<String> results = Grids.getEnteredResults();
		String itemToRemove = results.get(0);

		// Delete from database
		Connection c = null;
		try {
			c = SqliteHelper.getConn();
			Statement deleteStatement = c.createStatement();
			String deleteQuery = "DELETE FROM Menu WHERE Item_Name = '"
					+ itemToRemove + "';";
			deleteStatement.execute(deleteQuery);
		} catch (Exception ex) {
			System.err
			.println("Database Call Failure in removeMenuItem.");
			System.err.println(ex.getClass().getName() + ": "
					+ ex.getMessage());
		}
		Grids.deleteResult(menuHeaders);
		newGridsWindow();
	}//end deleteMenuItems method


	/**
	 * Opens up a selected menu item from the grid and allows the user to edit the menu item.  Should the information
	 * pass parsing the changes are then saved to the database and displayed to the user
	 */
	private void editMenuItems() {
		// Obtain the results from the highlighted row
		ArrayList<String> results = Grids.getEnteredResults();
		if (results != null) {
			// Obtain the item name for the update statement.
			String itemToModify = results.get(0);

			ArrayList<String> modresults = PopUp.runMenuItem(results);
			// if a parsing error is found pass the arraylist back to
			// runmenuItem
			while (modresults != null
					&& modresults.get(modresults.size() - 1).equals(
							"ERROR")) {
				modresults = PopUp.runMenuItem(modresults);
			}
			if (modresults != null) {
				// Run update on the database.
				Connection c = null;
				try {
					c = SqliteHelper.getConn();
					Statement updateStatement = c.createStatement();

					String updateQuery = "UPDATE Menu SET Item_Name = '"
							+ modresults.get(0)
							+ "', Item_Price = "
							+ modresults.get(1)
							+ ", Item_Activity = '"
							+ modresults.get(2)
							+ "', General_Cat = '"
							+ modresults.get(3)
							+ "', Specific_Cat = '"
							+ modresults.get(4)
							+ "' WHERE Item_Name = '"
							+ itemToModify
							+ "';";

					updateStatement.execute(updateQuery);
				} catch (Exception ex) {
					System.err
					.println("Database Call Failure in editMenuItem.");
					System.err.println(ex.getClass().getName() + ": "
							+ ex.getMessage());
				}

				Grids.modifyResult(modresults);
				newGridsWindow();
			}
		}
	}//end editMenuItems method

	/**
	 * Creates a JOptionPane window for a user to fill out information for a new menu item.  If the information parses
	 * the menu item will be added to the database and displayed to the user.
	 */
	private void addMenuItems() {
		//Grids.unHighlightRow();
		// A blank arraylist is used if a parsing error is found so
		// previous data entered is not lost
		ArrayList<String> blank = new ArrayList<String>();
		for (int i = 0; i < menuHeaders.size(); i++) {
			blank.add(null);
		}
		ArrayList<String> results = PopUp.runMenuItem(blank);
		// if a parsing error is found pass the arraylist back to
		// runManageEmployee
		while (results != null
				&& results.get(results.size() - 1).equals("ERROR")) {
			results = PopUp.runMenuItem(results);
		}
		if (results != null) {
			// Add the results to the database
			Connection c = null;
			try {
				c = SqliteHelper.getConn();
				Statement insertStatement = c.createStatement();

				// Inserts using the result arraylist for values. The
				// NULL is so the database will auto-increment the item
				// ID for the Primary Key.
				String insertQuery = "INSERT INTO Menu VALUES (NULL, '"
						+ results.get(0) + "', " + results.get(1)
						+ ", '" + results.get(2) + "', '"
						+ results.get(3) + "', '" + results.get(4) + "');";

				insertStatement.execute(insertQuery);
			} catch (Exception ex) {
				System.err
				.println("Database Call Failure in addMenuItem.");
				System.err.println(ex.getClass().getName() + ": "
						+ ex.getMessage());
			}

			Grids.addNewResult(results, menuHeaders);
			newGridsWindow();
		}
	}//End addMenuItems method

	/**
	 * Removes an employee from the database and the display
	 */
	private void deleteEmployee() {
		ArrayList<String> results = Grids.getEnteredResults();
		String empToRemove = results.get(1);
		// Database call to remove an employee
		Connection c = null;
		try {
			c = SqliteHelper.getConn();
			Statement empDeleteStatement = c.createStatement();
			String empDeleteQuery = "DELETE FROM Employee WHERE Employee_ID = " + empToRemove + ";";				
			empDeleteStatement.executeUpdate(empDeleteQuery);

		} catch (Exception ex) {
			System.err
			.println("Database Call Failure in removeemployee.");
			System.err.println(ex.getClass().getName() + ": "
					+ ex.getMessage());

		}
		Grids.deleteResult(empHeaders);
		newGridsWindow();
	}//End deleteEmployee method

	/**
	 * Opens up a JOptionPane window for the user to modify any employee in the database.  The information is parsed and if 
	 * it passes then the changes are added to the database and displayed on the grid
	 */
	private void editEmployee() {
		// Obtain the results from the highlighted row
		ArrayList<String> results = Grids.getEnteredResults();
		String empToModify;
		if (results != null) {
			empToModify = results.get(1);
			ArrayList<String> modResults = PopUp
					.runManageEmployee(results);
			// if a parsing error is found pass the arraylist back to
			// runManageEmployee
			while (modResults != null
					&& modResults.get(modResults.size() - 1).equals(
							"ERROR")) {
				modResults = PopUp.runManageEmployee(modResults);
			}
			if (modResults != null) {
				// Edit employee in the database
				Connection c = null;
				try {
					c = SqliteHelper.getConn();

					Statement empUpdateStatement = c.createStatement();
					String newEmpName = modResults.get(0);
					String newEmpPass = modResults.get(1);
					String newEmpHours = modResults.get(2);
					String newEmpJobCode = null;

					switch (modResults.get(3)) {
					case "Hostess":
						newEmpJobCode = "0";
						break;
					case "Server":
						newEmpJobCode = "1";
						break;
					case "Manager":
						newEmpJobCode = "2";
						break;
					}
					String newEmpNotes = modResults.get(4);

					String empUpdateQuery = "UPDATE Employee SET Employee_ID = "
							+ newEmpPass
							+ ", Job_Code = "
							+ newEmpJobCode
							+ ", Notes = '"
							+ newEmpNotes
							+ "', Weekly_Hours = "
							+ newEmpHours
							+ ", FullName = '"
							+ newEmpName
							+ "' WHERE Employee_ID = "
							+ empToModify + ";";

					empUpdateStatement.executeUpdate(empUpdateQuery);

				} catch (Exception ex) {
					System.err
					.println("Database Call Failure in editemployee.");
					System.err.println(ex.getClass().getName() + ": "
							+ ex.getMessage());

				}

				Grids.modifyResult(modResults);
				newGridsWindow();
			}
		}
	}//End editEmployee method

	/**
	 * Opens up a JOptionPane window for the user to fill out for a new employee.  The information is parsed and if 
	 * it passes then the employee is added to the database and displayed on the grid
	 */
	private void addEmployee() {
		//Grids.unHighlightRow();
		// A blank arraylist is used if a parsing error is found so
		// previous data entered is not lost
		ArrayList<String> blank = new ArrayList<String>();
		for (int i = 0; i < empHeaders.size(); i++) {
			blank.add(null);
		}
		ArrayList<String> results = PopUp.runManageEmployee(blank);
		// if a parsing error is found pass the arraylist back to
		// runManageEmployee
		while (results != null
				&& results.get(results.size() - 1).equals("ERROR")) {
			results = PopUp.runManageEmployee(results);
		}
		if (results != null) {
			// Insert employee into the database
			Connection c = null;
			try {
				c = SqliteHelper.getConn();

				Statement empInsertStatement = c.createStatement();
				String newEmpName = results.get(0);
				String newEmpPass = results.get(1);
				String newEmpHours = results.get(2);
				String newEmpJobCode = null;

				switch (results.get(3)) {
				case "Hostess":
					newEmpJobCode = "0";
					break;
				case "Server":
					newEmpJobCode = "1";
					break;
				case "Manager":
					newEmpJobCode = "2";
					break;
				}
				String newEmpNotes = results.get(4);

				String empInsertQuery = "INSERT INTO Employee VALUES ("
						+ newEmpPass + ", " + newEmpJobCode + ", '"
						+ newEmpNotes + "', " + newEmpHours + ", '"
						+ newEmpName + "');";

				empInsertStatement.executeUpdate(empInsertQuery);

			} catch (Exception ex) {
				System.err
				.println("Database Call Failure in addemployee.");
				System.err.println(ex.getClass().getName() + ": "
						+ ex.getMessage());

			}

			Grids.addNewResult(results, empHeaders);
			newGridsWindow();
		}

	}//End addEmployee method

	/**
	 * Calls to the Grids class to remove an employee from the database and display
	 */
	private void deleteReservation() {

		/**** NEED DATABASE CALL FOR RESERVATION/WAITLIST ****/ 

		Grids.deleteResult(resHeaders);	
		newGridsWindow();
	}//End deleteReservation


	/**
	 * From the edit button action listener the user is prompted for information and the system attempts to parse that information
	 * before submitting to the database
	 */
	private void editReservation() {

		/**** NEED DATABASE CALL FOR RESERVATION/WAITLIST ****/ 

		// Obtain the results from the highlighted row
		ArrayList<String> results = Grids.getEnteredResults();
		if (results != null) {
			ArrayList<String> oldInfo = new ArrayList<>();
			oldInfo.addAll(results);
			ArrayList<String> modResults = PopUp.runReservation(results);
			// if a parsing error is found pass the arraylist back to
			// runReservation
			while (modResults != null
					&& modResults.get(modResults.size() - 1).equals(
							"ERROR")) {
				modResults = PopUp.runReservation(modResults);
			}
			if (modResults != null) {
				String partyNumToModify = oldInfo.get(2);
				String nameToModify = oldInfo.get(3);
				SqliteHelper.editReservation(modResults, nameToModify, partyNumToModify);
				Grids.modifyResult(modResults);
				newGridsWindow();
			}
		}
	}//End editReservation method


	/**
	 * From the add button action listener the user is prompted for information and the system attempts to parse that information
	 * before submitting to the database
	 */
	private void addReservation() {
		//Grids.unHighlightRow();
		/**** NEED DATABASE CALL FOR RESERVATION/WAITLIST ****/ 

		// A blank arraylist is used if a parsing error is found so
		// previous data entered is not lost
		ArrayList<String> blank = new ArrayList<String>();
		for (int i = 0; i < resHeaders.size(); i++) {
			blank.add(null);
		}
		ArrayList<String> results = PopUp.runReservation(blank);
		// if a parsing error is found pass the arraylist back to
		// runManageEmployee
		while (results != null
				&& results.get(results.size() - 1).equals("ERROR")) {
			results = PopUp.runReservation(results);
		}
		if (results != null) {
			SqliteHelper.InsertReservation(results.get(0), results.get(1), Integer.parseInt(results.get(2)), results.get(3), results.get(4), results.get(5));
			Grids.addNewResult(results, resHeaders);
			newGridsWindow();
		}
	}//End addReservation method
	
	/**
	 * Calls to the Grids class to remove an employee from the database and display
	 */
	private void deleteWaitList() {

		/**** NEED DATABASE CALL FOR RESERVATION/WAITLIST ****/ 

		Grids.deleteResult(resHeaders);	
		newGridsWindow();
	}//End deleteReservation
	
	/**
	 * From the edit button action listener the user is prompted for information and the system attempts to parse that information
	 * before submitting to the database
	 */
	private void editWaitList() {

		/**** NEED DATABASE CALL FOR RESERVATION/WAITLIST ****/ 

		// Obtain the results from the highlighted row
		ArrayList<String> results = Grids.getEnteredResults();
		if (results != null) {

			ArrayList<String> modResults = PopUp.runReservation(results);
			// if a parsing error is found pass the arraylist back to
			// runReservation
			while (modResults != null
					&& modResults.get(modResults.size() - 1).equals(
							"ERROR")) {
				modResults = PopUp.runReservation(modResults);
			}
			if (modResults != null) {
				Grids.modifyResult(modResults);
				newGridsWindow();
			}
		}
	}//End editReservation method


	/**
	 * From the add button action listener the user is prompted for information and the system attempts to parse that information
	 * before submitting to the database
	 */
	private void addWaitList() {
		//Grids.unHighlightRow();
		/**** NEED DATABASE CALL FOR RESERVATION/WAITLIST ****/ 

		// A blank arraylist is used if a parsing error is found so
		// previous data entered is not lost
		ArrayList<String> blank = new ArrayList<String>();
		for (int i = 0; i < resHeaders.size(); i++) {
			blank.add(null);
		}
		ArrayList<String> results = PopUp.runReservation(blank);
		// if a parsing error is found pass the arraylist back to
		// runManageEmployee
		while (results != null
				&& results.get(results.size() - 1).equals("ERROR")) {
			results = PopUp.runReservation(results);
		}
		if (results != null) {
			SqliteHelper.InsertReservation(results.get(0), results.get(1), Integer.parseInt(results.get(2)), results.get(3), results.get(4), results.get(5));
			Grids.addNewResult(results, resHeaders);
			newGridsWindow();
		}
	}//End addReservation method

	/**
	 * Builds a Panel that displays the username and time
	 */
	private void buildNameBar() {
		nameBar = new JPanel();
		nameBar.setLayout(new GridLayout(1, 1));
		nameBar.setPreferredSize(new Dimension(500, 150));
		nameBar.setMinimumSize(new Dimension(500, 150));

		nameTime = buildNameTime(userName, new Date());
		nameBar.add(nameTime);	
		leftPanel.add(nameBar);
	}//End buildNameBar method


	/**
	 * Create a button that displays the user's name and time
	 * @param name - the user's name
	 * @param time - the current time
	 * @return JButton - the button (unselectable) that contains the user's name and time
	 */
	private JLabel buildNameTime(String name, Date time) {
		JLabel userInfo = new JLabel();
		userInfo.setHorizontalAlignment(SwingConstants.CENTER);
		DateFormat dateFormat = new SimpleDateFormat("HH:mm");
		userInfo.setText("<html>" + name + "<br />" + dateFormat.format(time)
				+ "</html>");
		userInfo.setFont(new Font("Arial", Font.PLAIN, 40));

		return userInfo;
	}//End buildNameTime method


	/**
	 * Creates the return to Main Menu button that reside at the bottom of the GridsWindow
	 */
	private void buildBottomGridPanel(){
		JPanel mainMenu = new JPanel();
		mainMenu.setLayout(new FlowLayout());
		mainMenu.setBackground(GUI.newTeal);

		JButton menuExit = new JButton("Main Menu");
		menuExit.setFont(new Font("Arial", Font.PLAIN, 40));
		menuExit.setPreferredSize(new Dimension(600, 75));
		menuExit.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Grids.setHighLightFalse();
				newGUIWindow();
			}
		});//End ActionListener

		mainMenu.add(menuExit);
		bottomPanel.add(mainMenu);	
	}
	//End of buildBottomOrderPanel

	/**
	 * Initializes the panels to be placed on Main Panel
	 */
	private void initializePanels() {
		leftPanel = new JPanel();
		leftPanel.setLayout(new BorderLayout());

		centerPanel = new JPanel();
		centerPanel.setLayout(new BorderLayout());

		bottomPanel = new JPanel();	
		bottomPanel.setLayout(new FlowLayout());
		bottomPanel.setBackground(GUI.newTeal);

	}//End initializePanels method


	/**
	 * Captures the name of the button that was clicked
	 * @param buttonClicked - the String name of the button pressed from the GUI class Action Listener
	 */
	public static void setButtonNameText(String buttonClicked) {
		buttonName = buttonClicked;
	}//End setButtonNameText method

	/**
	 * Establishes which manager button was click from the GUI class Action Listener
	 * @param choice (0 for reservations, 1 for employees, 2 for menu items)
	 */
	public static void setManagerSelection(int choice){
		managerSelection = choice;
	}//End setManagerSelection	

	/**
	 * Sets up the size of the window to take up the entire screen.  Main Panel is the container for the reminder of the class.
	 */
	private void setWindowSize() {
		Toolkit tk = Toolkit.getDefaultToolkit();
		xSize = ((int) tk.getScreenSize().getWidth());
		ySize = ((int) tk.getScreenSize().getHeight());

		//Establish full screen size
		mainPanel = new JPanel();
		mainPanel.setPreferredSize(new Dimension(xSize, ySize));
		mainPanel.setLayout(new BorderLayout());
	}//End setWindowSize method

	/**
	 * Creates a new instance of the GUI Class, removes the current mainPanel and replaces it with gui (GUI Class)
	 * and then validates and repaints the screen
	 */
	public void newGUIWindow(){
		GUI gui = new GUI(userID, userJobCode, userName);
		StartSystem.switchPanel(gui);
	}// End newGUIWindow method

	/**
	 * Creates a new instance of the GridsWindow Class, removes the current mainPanel and replaces it with gWindow (GridsWindow Class)
	 */
	public void newGridsWindow(){
		GridsWindow gWindow = new GridsWindow(userID, userJobCode, userName);
		StartSystem.switchPanel(gWindow);
	}// End newGridsWindow method


}//End of Class
